Syntax10.Scn.Fnt Syntax10i.Scn.Fnt StampElems Alloc 16 Dec 94 Syntax10b.Scn.Fnt MODULE DialogClocks; (** Markus Knasm ller 14 Sep 94 - (* This sourcecode uses parts of ClockElems - gri 18.3.91 *) IMPORT DialogFrames, Dialogs, DialogTexts, Display, Fonts, GraphicUtils, In, Input, Oberon, TextFrames, Texts, Viewers; CONST W* = 60; H* = 20; MM = 1; ticks = 300; (* Oberon.Time ticks per second*) TYPE Item* = POINTER TO ItemDesc; ItemDesc* = RECORD(Dialogs.ObjectDesc) END; Time* = RECORD timeStamp*, dateStamp*: LONGINT END; NotifyMsg = RECORD(Display.FrameMsg) new: Time END; old*: Time; (** displayed Time *) wakeUp: LONGINT; (* overflow in 82.8 days *) fnt: Fonts.Font; Task: Oberon.Task; PROCEDURE Format (time: LONGINT; VAR s: ARRAY OF CHAR); VAR i: INTEGER; PROCEDURE Pair (x: LONGINT); BEGIN s[i] := CHR(x DIV 10 + 30H); INC(i); s[i] := CHR(x MOD 10 + 30H); INC(i) END Pair; BEGIN i := 0; Pair(time DIV 4096 MOD 32); s[i] := ":"; INC(i); Pair(time DIV 64 MOD 64); s[i] := ":"; INC(i); Pair(time MOD 64); s[i] := 0X END Format; PROCEDURE (c: Item) Draw* (x, y: INTEGER; f: Display.Frame); (** displays the object at (x, y) in frame f *) VAR mode, w, h, ox, oy, cx, yh: INTEGER; str: ARRAY 12 OF CHAR; BEGIN c.GetDim (ox, oy, w, h); IF c.selected THEN mode := Display.invert ELSE mode := Display.paint END; yh := y + (h DIV 2) - ((fnt.minY + fnt.maxY) DIV 2); Format (old.timeStamp, str); IF h - (yh - y) > fnt.maxY THEN GraphicUtils.DrawString (f, str, x + 3, yh, w - 4, fnt, mode, GraphicUtils.center, cx) END END Draw; PROCEDURE (c: Item) Print* (x, y: INTEGER); (** prints the object at printer coordinates (x, y) *) VAR w, h, ox, oy, cx, yh: INTEGER; str: ARRAY 12 OF CHAR; time: Time; fnth: LONGINT; BEGIN c.GetPDim (ox, oy, w, h); fnth := ((fnt.maxY - fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2; yh := y + (h DIV 2) - SHORT (fnth); Oberon.GetClock (time.timeStamp, time.dateStamp); Format (time.timeStamp, str); IF h - (yh - y) > SHORT(fnt.maxY * Dialogs.dUnit DIV Dialogs.pUnit) THEN GraphicUtils.PrintString (str, x + 3, yh, w - 4, fnt, GraphicUtils.center, cx) END END Print; PROCEDURE (c: Item) Copy* (VAR dup: Dialogs.Object); (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *) VAR x: Item; BEGIN IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; c.Copy^ (dup); END Copy; PROCEDURE (c: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel); VAR keysum: SET; t: Texts.Text; BEGIN IF keys = {MM} THEN keysum := keys; REPEAT Input.Mouse(keys, x, y); keysum := keysum + keys; Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y) UNTIL keys = {}; IF (keysum = {MM}) & (c.cmd[0] # 0X) THEN DialogTexts.GetParText (c.par, c.panel, t); c.CallCmd (f, Viewers.This (x, y), t) END ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y) END END Track; PROCEDURE (c: Item) Redraw* (f: Display.Frame; x, y: INTEGER; old, new: Time); (** redraws the item at (x, y) in frame f - the time changed from old to new *) BEGIN IF c.selected THEN RETURN END; c.Hide; c.Restore END Redraw; PROCEDURE (c: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg); (** handles messages which were sent to frame f *) VAR x, y, w, h: INTEGER; BEGIN c.Handle^ (f, m); WITH f: DialogFrames.Frame DO WITH m: Oberon.InputMsg DO IF m.id = Oberon.track THEN c.Track (m.X, m.Y, m.keys, f, f.panel) END | m: NotifyMsg DO c.GetDim (x, y, w, h); x := x + f.X; y := y + f.Y + f.H; c.Redraw (f, x, y, old, m.new) ELSE END ELSE END END Handle; PROCEDURE Clock; VAR msg: NotifyMsg; BEGIN IF Oberon.Time () >= wakeUp THEN Oberon.GetClock (msg.new.timeStamp, msg.new.dateStamp); IF msg.new.timeStamp # old.timeStamp THEN wakeUp := Oberon.Time () + ticks * 15 DIV 16; Viewers.Broadcast (msg); old := msg.new ELSE wakeUp := Oberon.Time () + ticks DIV 16 END END END Clock; PROCEDURE Insert*; (** Insert ([name] [x y w h] | ^ ) inserts a clock - item in the panel containing the caret position *) VAR x, y, x1, y1, w, h: INTEGER; c: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; BEGIN NEW (c); DialogFrames.GetCaretPosition (p, x, y); IF (p # NIL) THEN c.Init; In.Open; In.Name (name); IF ~In.Done THEN COPY ("", name); In.Open END; c.SetName (name); In.Int (x1); In.Int (y1); In.Int (w); In.Int (h); IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H ELSE IF w < 0 THEN w := W END; IF h < 0 THEN h := H END END; c.SetDim (x1, y1, w, h, FALSE); p.Insert (c, FALSE) ELSE Dialogs.res := Dialogs.noPanelSelected END; IF Dialogs.res # 0 THEN Dialogs.Error ("DialogClocks") END; END Insert; BEGIN Oberon.GetClock (old.timeStamp, old.dateStamp); fnt := Fonts.This ("Syntax10.Scn.Fnt"); NEW (Task); Task.safe := FALSE; Task.handle := Clock; Oberon.Install (Task); END DialogClocks.